package cn.jesin.ssmss01.vo;

import cn.hutool.core.util.StrUtil;
import cn.jesin.ssmss01.common.LoginType;
import cn.jesin.ssmss01.common.OthType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

/**
 * @author 谷汉斌
 * @description 该类主要用来接收前端传递的授权信息
 * @createTime 2024/8/13 下午2:07
 */
@Data
@Builder
@Schema(description = "授权信息类")
public class OtherAuthInfo {
    @Schema(description = "用户名")
    private String username;
    @Schema(description = "手机号")
    private String phone;
    @Schema(description = "邮箱")
    private String email;
    @Schema(description = "密码")
    private String password;
    @Schema(description = "验证码")
    private String code;
    @Schema(description = "平台类型")
    private String othType;
    @Schema(description = "登录方式")
    private String loginType;

    public String oAuthOnlyId() {
        if (StrUtil.isNotBlank(this.phone)) {
            this.othType = OthType.PHONE.getType();
            return this.phone;
        } else if (StrUtil.isNotBlank(this.email)) {
            this.othType = OthType.EMAIL.getType();
            return this.email;
        }
        return this.username;
    }

    public String getOthType() {
        if (StrUtil.isNotBlank(this.phone)) {
            this.othType = OthType.PHONE.getType();
            return this.othType;
        } else if (StrUtil.isNotBlank(this.email)) {
            this.othType = OthType.EMAIL.getType();
            return this.othType;
        }
        return OthType.USERNAME.getType();
    }

    public String getCredintials() {
        if (StrUtil.isNotBlank(this.code)) {
            return this.code;
        } else if (StrUtil.isNotBlank(this.password)) {
            return this.password;
        }
        return null;
    }

    public String getLoginType() {
        if (StrUtil.isNotBlank(this.code)) {
            this.loginType = LoginType.VERIFICATION_CODE_LOGIN.getType();
        } else if (StrUtil.isNotBlank(this.password)) {
            this.loginType = LoginType.PASSWORD_LOGIN.getType();
        }
        return this.loginType;
    }
}
